const Router = require('koa-router')
const axios = require('axios')

const route = new Router({ prefix: '/api/order' })

route.post('/pay', async ctx => {
    const { openid } = ctx.request.body
    let res = {
        success: false,
        data: {},
        error: {},
        msg: ''
    }

    try {
        let response = await axios.post(
            'http://wx.xinglong.tech/pay',
            { openid }
        )
        res.data = response.data
        console.log('支付消息: ', res.data)
    } catch (error) {
        console.error(error)
    }

    ctx.body = res
})

module.exports = route
